﻿using System;
using System.Collections.Generic;
using AIPASoft.Interfaces.Base;


namespace AIPASoft.Interfaces.Security
{
    public interface ISecurityDataProvider : IDisposable
    {

        #region Public Factories

        IUser CreateNewUser();
        IRole CreateNewRole();
        IPermission CreateNewPermission();
        IAuthorisation CreateNewAuthorisation();

        #endregion

        #region Add Entities

        DataProviderOperationResult AddUser(IUser user, out string result);
        DataProviderOperationResult AddRole(IRole role, out string result);
        DataProviderOperationResult AddPermission(IPermission permission, out string result);
        DataProviderOperationResult AddAuthorisation(IRole role, IPermission permission, out string result);
        DataProviderOperationResult AddAuthorisation(int roleID, int permissionID, out string result);

        #endregion
         
        #region Update Delete Entities
         
        DataProviderOperationResult DeleteUser(IUser user, out string result); 
        DataProviderOperationResult DeleteRole(IRole role, out string result, bool removeDependencies = false); 
        DataProviderOperationResult DeleteRole(string roleName, out string result);
        DataProviderOperationResult DeleteRole(int roleID, out string result); 
        DataProviderOperationResult DeletePermission(string permissionName, out string result);
        DataProviderOperationResult DeleteAuthorisation(int authorisationID, out string result); 
        bool UpdateRole(IRole role);
        bool UpdateUser(IUser user);
        
        #endregion

        #region Search Entities

        IUser FindUser(int userID);
        IUser FindUser(string userName);
        IRole FindRole(int roleID);
        IRole FindRole(string roleName);
        IPermission FindPermission(string permissionName);
        IPermission FindPermission(int permissionID);

        IEnumerable<IUser> GetAllUsers();
        List<IRole> GetAllRoles(bool ignoreDeletedRoles = false);
        List<IPermission> GetAllPermissions();
        List<IPermission> GetAllPermissions(int roleID);
        List<IPermission> GetAllPermissions(string userName);
        List<IPermission> GetAllPermissions(IUser user);
        IEnumerable<IAuthorisation> GetAllAuthorisations();
        List<IAuthorisation> GetAllAuthorisations(int roleID);

        #endregion
        
        #region Public Login Method

        IUserRealm Login(string username, string password); 

        #endregion
    }
}
